package org.jtools.logwrapper;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.jtools.logwrapper.proxy.impl.Log4JLoggerProxy;
import org.jtools.sanitizer.Sanitizer;
import org.jtools.sanitizer.impl.ExceptionSanitizer;
import org.jtools.sanitizer.impl.StringSanitizer;

public abstract class LoggerWrapper {

    private final static List<Sanitizer> sanitizers = new ArrayList<Sanitizer>();

    private static final String STR_AMEX = "[0-9]{12,15}";

    private static final String STR_DINERS = "[0-9]{12,15}";

    private static final String STR_MASTERCARD = "[0-9]{12,15}";

    private static final String STR_VISA = "4([0-9]{12,15})";

    static {
        sanitizers.add(new StringSanitizer(STR_VISA, STR_AMEX, STR_DINERS, STR_MASTERCARD));
        sanitizers.add(new ExceptionSanitizer(STR_VISA, STR_AMEX, STR_DINERS, STR_MASTERCARD));
    }

    public static void addSanitizer(Sanitizer sanitizer) {
        sanitizers.add(sanitizer);
    }

    public static Logger getLogger(Class<?> clazz) {
        return (Logger) getLogger(clazz.getName());
    }

    public static Logger getLogger(String className) {
        return new Log4JLoggerProxy(className, sanitizers);
    }
}
